home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Graphics⁄Sound / Fudd Source / Fudd ƒ / MSG Shell ƒ / msg menus.c < prev    next >
Text File  |  1994-02-07  |  4KB  |  184 lines

  1. /**********************************************************************\
  2.  
  3. File:        msg menus.c
  4.  
  5. Purpose:    This module handles menu selections.
  6.  
  7.  
  8.  
  9. Fudd -=- convert text to Elmer Fudd talk
  10. Copyright ©1994, Mark Pilgrim
  11.  
  12. This program is free software; you can redistribute it and/or modify
  13. it under the terms of the GNU General Public License as published by
  14. the Free Software Foundation; either version 2 of the License, or
  15. (at your option) any later version.
  16.  
  17. This program is distributed in the hope that it will be useful,
  18. but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20. GNU General Public License for more details.
  21.  
  22. You should have received a copy of the GNU General Public License
  23. along with this program in a file named "GNU General Public License".
  24. If not, write to the Free Software Foundation, 675 Mass Ave,
  25. Cambridge, MA 02139, USA.
  26.  
  27. \**********************************************************************/
  28.  
  29. #include "msg graphics.h"
  30. #include "msg menus.h"
  31. #include "msg help.h"
  32. #include "msg prefs.h"
  33. #include "msg environment.h"
  34. #include "program globals.h"
  35. #include "fudd.h"
  36.  
  37. MenuHandle        gAppleMenu;
  38. MenuHandle        gFileMenu;
  39. MenuHandle        gEditMenu;
  40. MenuHandle        gOptionsMenu;
  41. MenuHandle        gHelpMenu;
  42.  
  43. void AdjustMenus(void)
  44. {
  45.     WindowPeek    theWindow;
  46.     int            kind;
  47.     int            i;
  48.     
  49.     if (!gInProgress)
  50.     {
  51.         EnableItem(gAppleMenu, 0);
  52.         EnableItem(gFileMenu, 0);
  53.         EnableItem(gEditMenu, 0);
  54.         EnableItem(gOptionsMenu, 0);
  55.     }
  56.     else
  57.     {
  58.         DisableItem(gAppleMenu, 0);
  59.         DisableItem(gFileMenu, 0);
  60.         DisableItem(gEditMenu, 0);
  61.         DisableItem(gOptionsMenu, 0);
  62.     }
  63.     
  64.     theWindow = (WindowPeek)FrontWindow();
  65.     kind = theWindow ? theWindow->windowKind : 0;
  66.     
  67.     if(kind < 0)
  68.         EnableItem(gEditMenu, 0);
  69.     else
  70.         DisableItem(gEditMenu, 0);
  71.     
  72.     if(theWindow)
  73.         EnableItem(gFileMenu, closeItem);
  74.     else
  75.         DisableItem(gFileMenu, closeItem);
  76.     
  77.     CheckItem(gOptionsMenu, showSaveItem, gShowSaveDialog);
  78.     CheckItem(gOptionsMenu, addSuffixItem, gAddSuffix);
  79.     CheckItem(gOptionsMenu, showProgressItem, gShowProgress);
  80. }
  81.  
  82. void HandleMenu(long mSelect)
  83. {
  84.     int            menuID = HiWord(mSelect);
  85.     int            menuItem = LoWord(mSelect);
  86.     
  87.     switch (menuID)
  88.     {
  89.         case appleMenu:
  90.             HandleAppleMenu(menuItem);
  91.             break;
  92.         case fileMenu:
  93.             HandleFileMenu(menuItem);
  94.             break;    
  95.         case editMenu:
  96.             HandleEditMenu(menuItem);
  97.             break;
  98.         case optionsMenu:
  99.             HandleOptionsMenu(menuItem);
  100.             break;
  101.         case helpMenu:
  102.             HandleHelpMenu(menuItem);
  103.             break;
  104.       }
  105. }
  106.  
  107. void HandleAppleMenu(int menuItem)
  108. {
  109.     GrafPtr        savePort;
  110.     Str255        name;
  111.     
  112.     if(menuItem == 1)
  113.         OpenTheWindow(kAbout);
  114.     if (menuItem == 2)
  115.         OpenTheWindow(kAboutMSG);
  116.     else if(menuItem > 4)
  117.     {
  118.         GetPort(&savePort);
  119.         GetItem(gAppleMenu, menuItem, name);
  120.         OpenDeskAcc(name);
  121.         SetPort(savePort);
  122.     }
  123. }
  124.  
  125. void HandleFileMenu(int menuItem)
  126. {
  127.     WindowPtr            theWindow;
  128.     int                    i;
  129.     Boolean                gotone;
  130.     
  131.     switch (menuItem)
  132.     {
  133.         case openItem:
  134.             NewConvert();
  135.             break;
  136.         case closeItem:
  137.             theWindow=FrontWindow();
  138.             gotone=FALSE;
  139.             for (i=0; (i<NUM_WINDOWS) && (!gotone); i++)
  140.                 gotone=(theWindow==gTheWindow[i]);
  141.                 
  142.             if (gotone)
  143.                 CloseTheWindow(i-1);
  144.             else
  145.                 DisposeWindow(theWindow);
  146.             
  147.             AdjustMenus();
  148.             break;
  149.         case quitItem:
  150.             gDone = TRUE;
  151.             break;
  152.     }
  153. }
  154.  
  155. void HandleEditMenu(int menuItem)
  156. {
  157.     SystemEdit(menuItem - 1);
  158. }
  159.  
  160. void HandleHelpMenu(int menuItem)
  161. {
  162.     gWhichHelp=menuItem;
  163.     UpdateHelpWindow();
  164. }
  165.  
  166. void HandleOptionsMenu(int menuItem)
  167. {
  168.     switch (menuItem)
  169.     {
  170.         case showSaveItem:
  171.             gShowSaveDialog=!gShowSaveDialog;
  172.             SaveThePrefs();
  173.             break;
  174.         case addSuffixItem:
  175.             gAddSuffix=!gAddSuffix;
  176.             SaveThePrefs();
  177.             break;
  178.         case showProgressItem:
  179.             gShowProgress=!gShowProgress;
  180.             SaveThePrefs();
  181.             break;
  182.     }
  183. }
  184.